package com.ticket.sass.provider.controller;

/**
 * @author ywb
 * @date 2024-03-29 14:38
 */

import com.ticket.sass.provider.business.TenantBusiness;
import com.ticket.sass.provider.business.impl.TenantBusinessImpl;
import com.ticket.sass.provider.dto.TenantListOutput;
import com.ticket.sass.provider.dto.input.tenant.TenantAddInput;
import com.ticket.sass.provider.dto.input.tenant.TenantListInput;
import com.ticket.sass.provider.dto.input.tenant.TenantUpdInput;
import com.ticket.sass.provider.dto.input.tenant.TransactionInput;
import com.ticket.sass.provider.dto.output.TransactionDataOutput;
import com.ticket.sass.provider.model.ResultModel;
import com.ticket.sass.provider.service.PageModel;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

@RestController
@RequestMapping("/tenants")
@Api(tags = "租户管理接口")
public class TenantController {
    
    final TenantBusiness tenantBusiness;
    
    public TenantController(TenantBusinessImpl tenantBusiness) {
        this.tenantBusiness = tenantBusiness;
    }
    
    @GetMapping
    @ApiOperation("获取租户列表")
    public ResultModel<PageModel<TenantListOutput>> getTenantList(TenantListInput input) {
        return ResultModel.success(tenantBusiness.list(input));
    }
    
    @PostMapping
    @ApiOperation("新增租户")
    public ResultModel<String> addTenant(@RequestBody TenantAddInput input) {
        tenantBusiness.add(input);
        return ResultModel.success();
    }
    
    @PutMapping
    @ApiOperation("更新租户")
    public ResultModel<String> updateTenant(@RequestBody TenantUpdInput input) {
        tenantBusiness.upd(input);
        return ResultModel.success();
    }
    
    @GetMapping("/transaction")
    @ApiOperation(value = "账目明细")
    public ResultModel<TransactionDataOutput> info(
        @Valid TransactionInput input
    ){
        return ResultModel.success(
            tenantBusiness.transactionInfo(input)
        );
    }
}

